//
//  ChangePasswordController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/27.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "ChangePasswordController.h"
#import "VerificationCodeView.h"

@interface ChangePasswordController ()
/**验证码视图*/
@property (nonatomic,strong)VerificationCodeView*codeView;
/**密码输入框*/
@property (nonatomic,strong)UITextField*pwdTextFile;
/**确认按钮*/
@property (nonatomic,strong)UIButton*commitBtn;
/**手机号*/
@property (nonatomic,strong)UILabel*phoneLabel;
@end

@implementation ChangePasswordController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改密码";
    [self createUI];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTextFiled) name:UITextFieldTextDidChangeNotification object:nil];
}
-(void)changeTextFiled{
    if (self.codeView.textFile.text.length >0 && self.pwdTextFile.text.length >0) {
        self.commitBtn.enabled = YES;
    }else{
        self.commitBtn.enabled = NO;
    }
}
-(void)createUI{
    UIView * oneLineView = UIView.new;
    oneLineView.backgroundColor = UIColorFromRGB(0xE9EEE7);
    
    UIView * twoLineView = UIView.new;
    twoLineView.backgroundColor = UIColorFromRGB(0xE9EEE7);

    [self.view addSubview:self.codeView];
    [self.view addSubview:oneLineView];
    [self.view addSubview:self.pwdTextFile];
    [self.view addSubview:twoLineView];

    [self.view addSubview:self.commitBtn];
    [self.view addSubview:self.phoneLabel];
    
    [self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(45);
        make.top.mas_equalTo(27);
        make.right.mas_equalTo(-45);
    }];
    
    [oneLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.codeView);
        make.height.mas_equalTo(0.5);
        make.top.mas_equalTo(self.codeView.mas_bottom).offset(8);
    }];
    [self.pwdTextFile mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.codeView);
        make.top.mas_equalTo(oneLineView.mas_bottom).offset(25);
//        make.height.mas_equalTo(30);
    }];
    [twoLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.codeView);
        make.height.mas_equalTo(0.5);
        make.top.mas_equalTo(self.pwdTextFile.mas_bottom).offset(8);
    }];
    
    [self.commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.codeView);
        make.height.mas_equalTo(47);
        make.top.mas_equalTo(twoLineView.mas_bottom).offset(24);
    }];
    
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(self.commitBtn.mas_bottom).offset(8);
    }];
}
-(VerificationCodeView*)codeView{
    if(!_codeView){
        _codeView=[[VerificationCodeView alloc] initWithFrame:CGRectZero];
        _codeView.lineView.hidden = YES;
        _codeView.countdown.textColor = UIColorFromRGB(0x009966);
        kWeakSelf(weakSelf);
        _codeView.downBlcok = ^{
            [weakSelf getDownAction:weakSelf.codeView.countdown];
        };

    }
    return _codeView;
}
-(UITextField*)pwdTextFile{
    if(!_pwdTextFile){
        _pwdTextFile=[[UITextField alloc] initWithFrame:CGRectZero];
        _pwdTextFile.placeholder = @"请输入新的密码（6-20位英文或字母";
        _pwdTextFile.placeholderColor = UIColorFromRGB(0xC2CEC5);
        _pwdTextFile.placeholderFont = PingFangSC_Regular(16);
        
    }
    return _pwdTextFile;
}
-(UIButton*)commitBtn{
    if(!_commitBtn){
        _commitBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        [_commitBtn setBackgroundImage:[UIImage createImageWithColor:UIColorFromRGB(0x009966)] forState:UIControlStateNormal];
        [_commitBtn setTitle:@"确认" forState:UIControlStateNormal];
        _commitBtn.titleLabel.font = PingFangSC_Medium(18);
        _commitBtn.enabled = NO;
    }
    return _commitBtn;
}
-(UILabel*)phoneLabel{
    if(!_phoneLabel){
        _phoneLabel=[UILabel new];
        _phoneLabel.textColor = UIColorFromRGB(0xC2CEC5);
        _phoneLabel.font = PingFangSC_Regular(14);
        _phoneLabel.text = @"已向手机186*****505发送验证码";
    }
    return _phoneLabel;
}
@end
